package com.qf.lanzhou.blog.api.pojo.entity;

/**
 * @author jack
 */
public class Page {
    private Integer pageIndex;//页码
    private Integer pageSize = 5;//每页多少行数据
    private Integer totalCounts; //总行数
    private Integer totalPage;//总页数
    private Integer startRow;//起始行

    public Page(Integer pageIndex) {
        this.pageIndex = pageIndex;
        this.setStartRow((pageIndex-1) * pageSize);
    }

    public Page(Integer pageIndex, Integer pageSize) {
        this.pageIndex = pageIndex;
        this.pageSize = pageSize;
        this.setStartRow((pageIndex-1) * pageSize);
    }

    public Integer getPageIndex() {
        return pageIndex;
    }

    public void setPageIndex(Integer pageIndex) {
        this.pageIndex = pageIndex;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getTotalCounts() {
        return totalCounts;
    }

    public void setTotalCounts(Integer totalCounts) {
        this.totalCounts = totalCounts;
        //总页数  总行数除以每页大小 等于0则为总行数除以每页大小 不为零则为总行数除以每页大小+1
        this.setTotalPage(totalCounts % pageSize==0 ? totalCounts/pageSize:totalCounts/pageSize+1);
    }

    public Integer getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(Integer totalPage) {
        this.totalPage = totalPage;
    }

    public Integer getStartRow() {
        return startRow;
    }

    public void setStartRow(Integer startRow) {
        this.startRow = startRow;
    }
}
